var Event = {
	InitBeijing: function(address){
		var listFn = function(address){
			$ajax({
				url: "/event/bj",
				data: {
					address: 0
				},
				success: function(res) {
					var items = res.result.results;
					SetLS("elist0", items);
					var html = "";
					if(!items||items.length==0||items==undefined){
                       html += '<div class="">'+
                                        '<div class="tx-c umt_p60">'+(CurrentUser.category==30?"亲,当前城市还没有老外的活动信息哦！":"There is no information at this moment!")+'</div>'+
                                '</div>';    
                    }
					for (var i=0; i<items.length; ++i) {
						//var photo = items[i].photo && items[i].photo[0] || "../img/icon_event.png";
						var photo = items[i].photo.length == 0 ? "../img/activity1.png" : Core.IMG_VER+items[i].photo[0];
						html += '<div class="ub up_list2" ontouchstart="zy_touch()" onclick="Event.jumpDetail(\''+ i +'\',\''+0+'\')">'+
                                '  <div class="ub up_list3 detailEvt uw100">'+
                                '     <div class="ub ub-ver uml_1 umt_11">'+     
                                '        <div class="ub umt_1">' +        
                                '            <div class="ub-img uw1p2 uh1p2 im_set_icon3"></div>'+
                                '           <div class="ub ub-ver ">'+ items[i].title + '</div>' +         
                                '        </div>' +     
                                '     <div class="ub umt_1">'+    
                                '        <div class="ub-img uw1p2 uh1p2 im_set_icon9"></div>' +       
                                '        <div class="ub ub-ver">'+ items[i].location +'</div>'+      
                                '     </div>'+  
                                '     <div class="ub umt_1">'+
                                '        <div class="ub-img uwp9 uh1 im_time"></div>'+
                                '        <div class="ub ub-ver">'+ (new Date(items[i].start)).pattern('yyyy-MM-dd') +'</div>'+  
                                '     </div>'+
                                '     <div class="ub umt_1 umb_p3">'+
                                '        <div class="ub-img uw1 uh1p2 im_set_icon1"></div>' + 
                                '        <div class="ub ub-ver pso_abs uw8">'+ items[i].fromName +'</div>'+
                                '        <div class="ub ub-ver uml_8l">'+  
                                '        <div class="ub-img uw1 uh1 im_icon_phone_no pso_abs"></div>'+
                                '        <div class="ub ub-ver pso_abs uw10 uml_1">'+items[i].phone+'</div>'+
                                '        </div>'+
                                '     </div>'+
                                '    </div>'+
                                '    <div class="ub ub-ver umt_pf6 ub-f1 ub_right">'+
                                '       <div class="uw8 uh7h5 ub_img  uml_8l ub-f1 pso_abs ub_right ub-ae ub-pe" style="background-image:url('+ photo +')"></div>'+   
                                '    </div>'+
                                '    <div class="ub ub-ver umt_5 ub-f1 ub_right umr_4f">'+
                                '        <div class="upp5 ufp7 ut-s umt_2f5 gray2 ub-f1 pso_abs ub_right ub-ae ub-pe">Post on '+ (new Date(items[i].create)).pattern('yyyy-MM-dd') +'</div>' + 
                                '    </div>'+
                                '     </div>'+
                                '  </div>'+
                                '</div>';
					}
					$("#beiJing").html(html);
				}
			});
		}	
		listFn(address);
	},
	InitShanghai: function(address){
        var listFn = function(address){
            $ajax({
                url: "/event/sh",
                data: {
                    address: 1
                },
                success: function(res) {
                    var items = res.result.results;
                    SetLS("elist1", items);
                    var html = "";
                    if(!items||items.length==0||items==undefined){
                       html += '<div class="">'+
                                        '<div class="tx-c umt_p60">'+(CurrentUser.category==30?"亲,当前城市还没有老外的活动信息哦！":"There is no information at this moment!")+'</div>'+
                                '</div>';    
                    }
                    for (var i=0; i<items.length; ++i) {
                        var photo = items[i].photo.length == 0 ? "../img/activity1.png" : Core.IMG_VER+items[i].photo[0];
                        html += '<div class="ub up_list2" ontouchstart="zy_touch()" onclick="Event.jumpDetail(\''+ i +'\',\''+1+'\')">'+
                                '  <div class="ub up_list3 detailEvt uw100">'+
                                '     <div class="ub ub-ver uml_1 umt_11">'+     
                                '        <div class="ub umt_1">' +        
                                '            <div class="ub-img uw1p2 uh1p2 im_set_icon3"></div>'+
                                '           <div class="ub ub-ver ">'+ items[i].title + '</div>' +         
                                '        </div>' +     
                                '     <div class="ub umt_1">'+    
                                '        <div class="ub-img uw1p2 uh1p2 im_set_icon9"></div>' +       
                                '        <div class="ub ub-ver">'+ items[i].location +'</div>'+      
                                '     </div>'+  
                                '     <div class="ub umt_1">'+
                                '        <div class="ub-img uwp9 uh1 im_time"></div>'+
                                '        <div class="ub ub-ver">'+ (new Date(items[i].start)).pattern('yyyy-MM-dd') +'</div>'+  
                                '     </div>'+
                                '     <div class="ub umt_1 umb_p3">'+
                                '        <div class="ub-img uw1 uh1p2 im_set_icon1"></div>' + 
                                '        <div class="ub ub-ver pso_abs uw8">'+ items[i].fromName +'</div>'+
                                '        <div class="ub ub-ver uml_8l">'+  
                                '        <div class="ub-img uw1 uh1 im_icon_phone_no pso_abs"></div>'+
                                '        <div class="ub ub-ver pso_abs uw10 uml_1">'+items[i].phone+'</div>'+
                                '        </div>'+
                                '     </div>'+
                                '    </div>'+
                                '    <div class="ub ub-ver umt_pf6 ub-f1 ub_right">'+
                                '       <div class="uw8 uh7h5 ub_img  uml_8l ub-f1 pso_abs ub_right ub-ae ub-pe" style="background-image:url('+ photo +')"></div>'+   
                                '    </div>'+
                                '    <div class="ub ub-ver umt_5 ub-f1 ub_right umr_4f">'+
                                '        <div class="upp5 ufp7 ut-s umt_2f5 gray2 ub-f1 pso_abs ub_right ub-ae ub-pe">Post on '+ (new Date(items[i].create)).pattern('yyyy-MM-dd') +'</div>' + 
                                '    </div>'+
                                '     </div>'+
                                '  </div>'+
                                '</div>';
                    }
                    $("#shangHai").html(html);
                }
            });
        }   
        listFn(address);
    },
    InitGuangzhou: function(address){
        var listFn = function(address){
            $ajax({
                url: "/event/gz",
                data: {
                    address: 2
                },
                success: function(res) {
                    var items = res.result.results;
                    SetLS("elist2", items);
                    var html = "";
                    if(!items||items.length==0||items==undefined){
                       html += '<div class="">'+
                                        '<div class="tx-c umt_p60">'+(CurrentUser.category==30?"亲,当前城市还没有老外的活动信息哦！":"There is no information at this moment!")+'</div>'+
                                '</div>';    
                    }
                    for (var i=0; i<items.length; ++i) {
                        var photo = items[i].photo.length == 0 ? "../img/activity1.png" : Core.IMG_VER+items[i].photo[0];
                        html += '<div class="ub up_list2" ontouchstart="zy_touch()" onclick="Event.jumpDetail(\''+ i +'\',\''+2+'\')">'+
                                '  <div class="ub up_list3 detailEvt uw100">'+
                                '     <div class="ub ub-ver uml_1 umt_11">'+     
                                '        <div class="ub umt_1">' +        
                                '            <div class="ub-img uw1p2 uh1p2 im_set_icon3"></div>'+
                                '           <div class="ub ub-ver ">'+ items[i].title + '</div>' +         
                                '        </div>' +     
                                '     <div class="ub umt_1">'+    
                                '        <div class="ub-img uw1p2 uh1p2 im_set_icon9"></div>' +       
                                '        <div class="ub ub-ver">'+ items[i].location +'</div>'+      
                                '     </div>'+  
                                '     <div class="ub umt_1">'+
                                '        <div class="ub-img uwp9 uh1 im_time"></div>'+
                                '        <div class="ub ub-ver">'+ (new Date(items[i].start)).pattern('yyyy-MM-dd') +'</div>'+  
                                '     </div>'+
                                '     <div class="ub umt_1 umb_p3">'+
                                '        <div class="ub-img uw1 uh1p2 im_set_icon1"></div>' + 
                                '        <div class="ub ub-ver pso_abs uw8">'+ items[i].fromName +'</div>'+
                                '        <div class="ub ub-ver uml_8l">'+  
                                '        <div class="ub-img uw1 uh1 im_icon_phone_no pso_abs"></div>'+
                                '        <div class="ub ub-ver pso_abs uw10 uml_1">'+items[i].phone+'</div>'+
                                '        </div>'+
                                '     </div>'+
                                '    </div>'+
                                '    <div class="ub ub-ver umt_pf6 ub-f1 ub_right">'+
                                '       <div class="uw8 uh7h5 ub_img  uml_8l ub-f1 pso_abs ub_right ub-ae ub-pe" style="background-image:url('+ photo +')"></div>'+   
                                '    </div>'+
                                '    <div class="ub ub-ver umt_5 ub-f1 ub_right umr_4f">'+
                                '        <div class="upp5 ufp7 ut-s umt_2f5 gray2 ub-f1 pso_abs ub_right ub-ae ub-pe">Post on '+ (new Date(items[i].create)).pattern('yyyy-MM-dd') +'</div>' + 
                                '    </div>'+
                                '     </div>'+
                                '  </div>'+
                                '</div>';
                    }
                    $("#guangZhou").html(html);
                }
            });
        }   
        listFn(address);
    },
    InitShenzhen: function(address){
        var listFn = function(address){
            $ajax({
                url: "/event/sz",
                data: {
                    address: 3
                },
                success: function(res) {
                    var items = res.result.results;
                    SetLS("elist3", items);
                    var html = "";
                    if(!items||items.length==0||items==undefined){
                       html += '<div class="">'+
                                        '<div class="tx-c umt_p60">'+(CurrentUser.category==30?"亲,当前城市还没有老外的活动信息哦！":"There is no information at this moment!")+'</div>'+
                                '</div>';    
                    }
                    for (var i=0; i<items.length; ++i) {
                        var photo = items[i].photo.length == 0 ? "../img/activity1.png" : Core.IMG_VER+items[i].photo[0];
                        html += '<div class="ub up_list2" ontouchstart="zy_touch()" onclick="Event.jumpDetail(\''+ i +'\',\''+3+'\')">'+
                                '  <div class="ub up_list3 detailEvt uw100">'+
                                '     <div class="ub ub-ver uml_1 umt_11">'+     
                                '        <div class="ub umt_1">' +        
                                '            <div class="ub-img uw1p2 uh1p2 im_set_icon3"></div>'+
                                '           <div class="ub ub-ver ">'+ items[i].title + '</div>' +         
                                '        </div>' +     
                                '     <div class="ub umt_1">'+    
                                '        <div class="ub-img uw1p2 uh1p2 im_set_icon9"></div>' +       
                                '        <div class="ub ub-ver">'+ items[i].location +'</div>'+      
                                '     </div>'+  
                                '     <div class="ub umt_1">'+
                                '        <div class="ub-img uwp9 uh1 im_time"></div>'+
                                '        <div class="ub ub-ver">'+ (new Date(items[i].start)).pattern('yyyy-MM-dd') +'</div>'+  
                                '     </div>'+
                                '     <div class="ub umt_1 umb_p3">'+
                                '        <div class="ub-img uw1 uh1p2 im_set_icon1"></div>' + 
                                '        <div class="ub ub-ver pso_abs uw8">'+ items[i].fromName +'</div>'+
                                '        <div class="ub ub-ver uml_8l">'+  
                                '        <div class="ub-img uw1 uh1 im_icon_phone_no pso_abs"></div>'+
                                '        <div class="ub ub-ver pso_abs uw10 uml_1">'+items[i].phone+'</div>'+
                                '        </div>'+
                                '     </div>'+
                                '    </div>'+
                                '    <div class="ub ub-ver umt_pf6 ub-f1 ub_right">'+
                                '       <div class="uw8 uh7h5 ub_img  uml_8l ub-f1 pso_abs ub_right ub-ae ub-pe" style="background-image:url('+ photo +')"></div>'+   
                                '    </div>'+
                                '    <div class="ub ub-ver umt_5 ub-f1 ub_right umr_4f">'+
                                '        <div class="upp5 ufp7 ut-s umt_2f5 gray2 ub-f1 pso_abs ub_right ub-ae ub-pe">Post on '+ (new Date(items[i].create)).pattern('yyyy-MM-dd') +'</div>' + 
                                '    </div>'+
                                '     </div>'+
                                '  </div>'+
                                '</div>';
                    }
                    $("#shenZhen").html(html);
                }
            });
        }   
        listFn(address);
    },
    InitOthers: function(address){
        var listFn = function(address){
            $ajax({
                url: "/event/qt",
                data: {
                    address: 4
                },
                success: function(res) {
                    var items = res.result.results;
                    SetLS("elist4", items);
                    var html = "";
                    if(!items||items.length==0||items==undefined){
                       html +='<div class="">'+
                                        '<div class="tx-c umt_p60">'+(CurrentUser.category==30?"亲,当前城市还没有老外的活动信息哦！":"There is no information at this moment!")+'</div>'+
                                '</div>';  
                    }else{
                    for (var i=0; i<items.length; ++i) {
                        var photo = items[i].photo.length == 0 ? "../img/activity1.png" : Core.IMG_VER+items[i].photo[0];
                        html += '<div class="ub up_list2" ontouchstart="zy_touch()" onclick="Event.jumpDetail(\''+ i +'\',\''+4+'\')">'+
                                '  <div class="ub up_list3 detailEvt uw100">'+
                                '     <div class="ub ub-ver uml_1 umt_11">'+     
                                '        <div class="ub umt_1">' +        
                                '            <div class="ub-img uw1p2 uh1p2 im_set_icon3"></div>'+
                                '           <div class="ub ub-ver ">'+ items[i].title + '</div>' +         
                                '        </div>' +     
                                '     <div class="ub umt_1">'+    
                                '        <div class="ub-img uw1p2 uh1p2 im_set_icon9"></div>' +       
                                '        <div class="ub ub-ver">'+ items[i].location +'</div>'+      
                                '     </div>'+  
                                '     <div class="ub umt_1">'+
                                '        <div class="ub-img uwp9 uh1 im_time"></div>'+
                                '        <div class="ub ub-ver">'+ (new Date(items[i].start)).pattern('yyyy-MM-dd') +'</div>'+  
                                '     </div>'+
                                '     <div class="ub umt_1 umb_p3">'+
                                '        <div class="ub-img uw1 uh1p2 im_set_icon1"></div>' + 
                                '        <div class="ub ub-ver pso_abs uw8">'+ items[i].fromName +'</div>'+
                                '        <div class="ub ub-ver uml_8l">'+  
                                '        <div class="ub-img uw1 uh1 im_icon_phone_no pso_abs"></div>'+
                                '        <div class="ub ub-ver pso_abs uw10 uml_1">'+items[i].phone+'</div>'+
                                '        </div>'+
                                '     </div>'+
                                '    </div>'+
                                '    <div class="ub ub-ver umt_pf6 ub-f1 ub_right">'+
                                '       <div class="uw8 uh7h5 img_size ub_img  uml_8l ub-f1 pso_abs ub_right ub-ae ub-pe" style="background-image:url('+ photo +')"></div>'+   
                                '    </div>'+
                                '    <div class="ub ub-ver umt_5 ub-f1 ub_right umr_4f">'+
                                '        <div class="upp5 ufp7 ut-s umt_2f5 gray2 ub-f1 pso_abs ub_right ub-ae ub-pe">Post on '+ (new Date(items[i].create)).pattern('yyyy-MM-dd') +'</div>' + 
                                '    </div>'+
                                '     </div>'+
                                '  </div>'+
                                '</div>';
                    }
                    $("#others").html(html);
                }
                }
            });
        }   
        listFn(address);
    },
	attendInit: function(address){
		var listFn = function(address){
			$ajax({
				url: "/event/attendList",
				data: {
					user: CurrentUser._id,
					address: address
				},
				success: function(res) {
					var items = res.result.results;
					SetLS("attendelist", items);
					var html = "";
					for (var i=0; i<items.length; ++i) {
						var photo = items[i].photo.length == 0 ? "../img/activity1.png" : Core.IMG_VER+items[i].photo[0];
						html += '<div class="ub up_list2" ontouchstart="zy_touch()" onclick="Event.jumpAttendDetail(\''+ i +'\')">'+
                                '  <div class="ub up_list3 detailEvt uw103">'+
                                '     <div class="ub ub-ver umt_11">'+     
                                '        <div class="ub umt_1">' +        
                                '            <div class="ub-img uw1p2 uh1p2 im_set_icon3"></div>'+
                                '           <div class="ub ub-ver ">'+ items[i].title + '</div>' +         
                                '        </div>' +     
                                '     <div class="ub umt_1">'+    
                                '        <div class="ub-img uw1p2 uh1p2 im_set_icon9"></div>' +       
                                '        <div class="ub ub-ver">'+ items[i].location +'</div>'+      
                                '     </div>'+  
                                '     <div class="ub umt_1">'+
                                '        <div class="ub-img uwp9 uh1 im_time"></div>'+
                                '        <div class="ub ub-ver">'+ (new Date(items[i].start)).pattern('yyyy-MM-dd') +'</div>'+  
                                '     </div>'+
                                '     <div class="ub umt_1 umb_p3">'+
                                '        <div class="ub-img uw1 uh1p2 im_set_icon1"></div>' + 
                                '        <div class="ub ub-ver pso_abs uw8">'+ items[i].fromName +'</div>'+
                                '        <div class="ub ub-ver uml_8l">'+  
                                '        <div class="ub-img uw1 uh1 im_icon_phone_no pso_abs"></div>'+
                                '        <div class="ub ub-ver pso_abs uw10 uml_1">'+items[i].phone+'</div>'+
                                '        </div>'+
                                '     </div>'+
                                '    </div>'+
                                '    <div class="ub ub-ver umt_pf6 ub-f1 ub_right">'+
                                '       <div class="uw8 uh7h5 ub_img  uml_8l ub-f1 pso_abs ub_right ub-ae ub-pe" style="background-image:url('+ photo +')"></div>'+   
                                '    </div>'+
                                '    <div class="ub ub-ver umt_5 ub-f1 ub_right umr_4f">'+
                                '        <div class="upp5 ufp7 ut-s umt_2f5 gray2 ub-f1 pso_abs ub_right ub-ae ub-pe">Post on '+ (new Date(items[i].create)).pattern('yyyy-MM-dd') +'</div>' + 
                                '    </div>'+
                                '     </div>'+
                                '  </div>'+
                                '</div>';
					}
					$("#attendList").html(html);
				}
			});
		}	
		listFn(address);
	},
	myInit: function(value){
		$ajax({
			url: "/event/myList",
			data: {from: CurrentUser._id},
			success: function(res) {
				var items = res.result.results;
				SetLS("myelist", items);
				var html = "";
				for (var i=0; i<items.length; ++i) {
					var photo = items[i].photo.length == 0 ? "../img/activity1.png" : Core.IMG_VER+items[i].photo[0];
					html += '<div class="ub up_list2" ontouchstart="zy_touch()" onclick="Event.jumpMyDetail(\''+ i +'\')">'+
                            '  <div class="ub up_list3 detailEvt uw100">'+
                            '     <div class="ub ub-ver umt_11">'+     
                            '        <div class="ub umt_1">' +        
                            '            <div class="ub-img uw1p2 uh1p2 im_set_icon3"></div>'+
                            '           <div class="ub ub-ver ">'+ items[i].title + '</div>' +         
                            '        </div>' +     
                            '     <div class="ub umt_1">'+    
                            '        <div class="ub-img uw1p2 uh1p2 im_set_icon9"></div>' +       
                            '        <div class="ub ub-ver">'+ items[i].location +'</div>'+      
                            '     </div>'+  
                            '     <div class="ub umt_1">'+
                            '        <div class="ub-img uwp9 uh1 im_time"></div>'+
                            '        <div class="ub ub-ver">'+ (new Date(items[i].start)).pattern('yyyy-MM-dd') +'</div>'+  
                            '     </div>'+
                            '     <div class="ub umt_1 umb_p3">'+
                            '        <div class="ub-img uw1 uh1p2 im_set_icon1"></div>' + 
                            '        <div class="ub ub-ver pso_abs uw8">'+ items[i].fromName +'</div>'+
                            '        <div class="ub ub-ver uml_8l">'+  
                            '        <div class="ub-img uw1 uh1 im_icon_phone_no pso_abs"></div>'+
                            '        <div class="ub ub-ver pso_abs uw10 uml_1">'+items[i].phone+'</div>'+
                            '        </div>'+
                            '     </div>'+
                            '    </div>'+
                            '    <div class="ub ub-ver umt_pf6 ub-f1 ub_right">'+
                            '       <div class="uw8 uh7h5 ub_img  uml_8l ub-f1 pso_abs ub_right ub-ae ub-pe" style="background-image:url('+ photo +')"></div>'+   
                            '    </div>'+
                            '    <div class="ub ub-ver umt_5 ub-f1 ub_right umr_4f">'+
                            '        <div class="upp5 ufp7 ut-s umt_2f5 gray2 ub-f1 pso_abs ub_right ub-ae ub-pe">Post on '+ (new Date(items[i].create)).pattern('yyyy-MM-dd') +'</div>' + 
                            '    </div>'+
                            '     </div>'+
                            '  </div>'+
                            '</div>';
				}
				$("#myList").html(html);
			}
		});
	},
	jumpDetail: function(i,index){
	    var item = "";
        if(index == "0"){
            item = GetLS("elist0")[i];
        }
        if(index == "1"){
            item = GetLS("elist1")[i];
        }
        if(index == "2"){
            item = GetLS("elist2")[i];
        }
        if(index == "3"){
            item = GetLS("elist3")[i];
        }
        if(index == "4"){
            item = GetLS("elist4")[i];
        }
        SetLS("event",item);
        if(item.from==CurrentUser._id){
          OpenNewWin("event_edit");
        }else{
          OpenNewWin("event_detail"); 
        }
		
	},	
	jumpAttendDetail: function(i){
		var item = GetLS("attendelist")[i];
		SetLS("event",item);
		OpenNewWin("event_detail");
	},
	jumpMyDetail: function(i){
		var item = GetLS("myelist")[i];
		SetLS("event",item);
		OpenNewWin("event_detail");
	},
	addContactInit:function(){
	   var event = GetLS("event");
	   $ajax({
            url: "/event/user",
            data: {
                from:event.from
            },
            success: function(res) {
               var user=res.result;
               SetLS("event_frienddetail",user);
               OpenNewWin("event_frienddetail");
            }
        });
	},
	persondetailInit: function() {
        var personfriend = GetLS("event_frienddetail");
        $("#id").text(personfriend._id);
        $("#from").text(personfriend.from);
        $("#photo").css("background-image", "url("+ Core.id2url(personfriend) +")");
        $("#name").text(personfriend.name +"　"+ (personfriend.sex?personfriend.sex:""));
        $("#phone").text(CurrentUser.category==30?"电话:"+personfriend.phone:"Phone:"+personfriend.phone);
        var wu=CurrentUser.category==30?"无":"No";
        $("#country").text(CurrentUser.category==30?"国家:"+ (personfriend.courntry?personfriend.courntry:wu):"Country:"+ (personfriend.courntry?personfriend.courntry:wu));
        $("#interest").text(CurrentUser.category==30?"爱好:"+ (personfriend.interest?personfriend.interest:wu):"Interest:"+ (personfriend.interest?personfriend.interest:wu));
    },
    ChatQuery: function() {
         SetLS("friendId",$("#id").text());
         SetLS("friendfrom",$("#from").text());
         SetLS("friendph",$("#phone").text());
         SetLS("friendnm",$("#name").text());
        var cid =CurrentUser._id;
        var fid = GetLS("friendId");
        var fph = ""+GetLS("friendph");
        var fph1=fph.substring(fph.indexOf(":")+1);
        var fnm = GetLS("friendnm");
        var cph=CurrentUser.phone;
        var adf=document.getElementById("btnCtn"); 
        var chf=document.getElementById("btnCtnChat");  
        if(CurrentUser.category==30){
                           if(cid==fid){
                               chf.setAttribute("style","display:none");
                              $alert("亲，不能添加自己为好友！");
                           }else{
                              var flag =false;
                              var length = CurrentUser.friends && CurrentUser.friends.length || 0;
                              for(var i=0; i<length; i++) {
                              var dbid=CurrentUser._id;
                              var fid = GetLS("friendId");
                              var dbfid=CurrentUser.friends[i].id;
                              var dbfr=CurrentUser.friends[i].from;
                              var st=CurrentUser.friends[i].status;
  
                                 var first = st==1;
                                 var second = (fid==dbfid || fid==dbfr);

                                 if((first&&second)==true){
                                     flag = true;
                                     adf.setAttribute("style","display:none");  
                                     SetLS("alist_chat", true);
                                     SetLS("chat_detail", GetLS("event_frienddetail"));
                                 }
                                 }  
                                 if(!flag){
                                    chf.setAttribute("style","display:none"); 
                                 }
                           }
                    }else{
                              if(cid==fid){
                                  chf.setAttribute("style","display:none");
                              return $alertEn("You can't add you as a friend!");
                              PCall("event_frienddetail","WinClose()");
                           }else{
                              var flag =false;
                              var length = CurrentUser.friends && CurrentUser.friends.length || 0;
                              for(var i=0; i<length; i++) {
                              var dbid=CurrentUser._id;
                              var fid = GetLS("friendId");
                              var dbfid=CurrentUser.friends[i].id;
                              var dbfr=CurrentUser.friends[i].from;
                              var st=CurrentUser.friends[i].status;
                                 var first = st==1;
                                 var second = (fid==dbfid || fid==dbfr);
                                 if((first&&second)==true){
                                     flag = true;
                                     adf.setAttribute("style","display:none");
                                     SetLS("alist_chat", true);
                                     SetLS("chat_detail", GetLS("event_frienddetail"));
                                 }
                                 }  
                                 if(!flag){
                                    chf.setAttribute("style","display:none");
                                 }
                           }  
                   }         
    },
	addContact:function(){
                     SetLS("friendId",$("#id").text());
                     SetLS("friendfrom",$("#from").text());
                     SetLS("friendph",$("#phone").text());
                     SetLS("friendnm",$("#name").text());
                    var cid =CurrentUser._id;
                    var fid = GetLS("friendId");
                    var fph = ""+GetLS("friendph");
                    var fph1=fph.substring(fph.indexOf(":")+1);
                    var fnm = GetLS("friendnm");
                    var cph=CurrentUser.phone; 
                    var adf=document.getElementById("btnCtn"); 
                    var chf=document.getElementById("btnCtnChat");  
                    if(CurrentUser.category==30){
                           if(cid==fid){
                               chf.setAttribute("style","display:none");
                              $alert("亲，不能添加自己为好友！");
                           }else{
                              var flag =false;
                              var length = CurrentUser.friends && CurrentUser.friends.length || 0;
                              for(var i=0; i<length; i++) {
                              var dbid=CurrentUser._id;
                              var fid = GetLS("friendId");
                              var dbfid=CurrentUser.friends[i].id;
                              var dbfr=CurrentUser.friends[i].from;
                              var st=CurrentUser.friends[i].status;
  
                                 var first = st==1;
                                 var second = (fid==dbfid || fid==dbfr);

                                 if((first&&second)==true){
                                     flag = true;
                                     adf.setAttribute("style","display:none");  
                                     SetLS("alist_chat", true);
                                     SetLS("chat_detail", GetLS("event_frienddetail"));
                                     OpenNewWin("chat_detail");
                                 }
                                 }  
                                 if(!flag){
                                    chf.setAttribute("style","display:none"); 
                                    OpenNewWin("activityevent_add_friend");    
                                 }
                           }
                    }else{
                              if(cid==fid){
                                  chf.setAttribute("style","display:none");
                              return $alertEn("You can't add you as a friend!");
                              PCall("event_frienddetail","WinClose()");
                           }else{
                              var flag =false;
                              var length = CurrentUser.friends && CurrentUser.friends.length || 0;
                              for(var i=0; i<length; i++) {
                              var dbid=CurrentUser._id;
                              var fid = GetLS("friendId");
                              var dbfid=CurrentUser.friends[i].id;
                              var dbfr=CurrentUser.friends[i].from;
                              var st=CurrentUser.friends[i].status;
                                 var first = st==1;
                                 var second = (fid==dbfid || fid==dbfr);
                                 if((first&&second)==true){
                                     flag = true;
                                     adf.setAttribute("style","display:none");
                                     SetLS("alist_chat", true);
                                     SetLS("chat_detail", GetLS("event_frienddetail"));
                                     OpenNewWin("chat_detail");
                                 }
                                 }  
                                 if(!flag){
                                    chf.setAttribute("style","display:none");
                                    OpenNewWin("activityevent_add_friend");    
                                 }
                           }  
                   }
        
    },
	detailInit: function(){
		var data = GetLS("event");
		$(".value").each(function(){
			if ($(this).attr("id") == "category"){
			    if(data.category == 7){
			        $(this).text(data.activity);
			    }else{
			        CurrentUser.category==30?$(this).text(eventArrText[data.category]):$(this).text(eventArrText1[data.category]);
			    }
			}else if ($(this).attr("id") == "start" || $(this).attr("id") == "end"){
				$(this).text(data[$(this).attr("id")]?new Date(data[$(this).attr("id")]).pattern("yyyy-MM-dd HH:mm"):"");
			}else{
				$(this).text(data[$(this).attr("id")]);
		    }
		});
		$("#contentd").text(data.content);
		//$("#photo").css("background-image", "url("+ data.photo +")");
		$("#create").text( (new Date(data.create)).pattern('yyyy-MM-dd HH:mm:ss'));
		$.each(data.photo,function(i,item){
			$("#photoList").append('<div data-photo="set_bg.png" class="uw100 umauto uptb_p5 photo"><img src="' + Core.id2url(item,"photo") + '" class="uw100"></div>');
		});
		$("#address").text(data.address);
            if(data.address==0){
               $("#address").text("BeiJing");
            }
            if(data.address==1){
               $("#address").text("ShangHai");
            }
            if(data.address==2){
               $("#address").text("GuangZhou");
            }
            if(data.address==3){
               $("#address").text("ShenZhens");
            }
            if(data.address==4){
               $("#address").text(data.addressOther);
            }
		$ajax({
            url: "/event/listname",
            data: data,
            success: function(res){
               var user = res.result;
               SetLS("addlist", user);
               var html = "";
               if(user.length== 0){
                   var pd=CurrentUser.category==30?"无":"No";
                   html += '<div style="margin-left:-1em;margin-top:-2.1em;">'+pd+'</div>';
                   $("#number").html(html);
                   return;
               }
               for (var i=0; i<user.length; ++i) {
                   var phone = CurrentUser.category==30?"电话:"+user[i].phone:"Phone:" + user[i].phone;
                   var addFd = CurrentUser.category==30?"添加好友":"Add Friend";
                    html += '<div class="ub ub-ac detailEvt" style="width:100%;border-bottom: 1px solid #cccccc;position:relative">'+
                            '     <div class="col_r" style="padding-left:1.5em;">'+(i+1)+'.</div>'+
                            '     <div class="ub ub-ver b_gra">'+
                            '         <div class="uw2 uh2 uc-ap50 ub_img_cover detailEvt" style="background-image:url('+ Core.id2url(user) +')"></div>'+
                            '         <div class="ub ub-ver" style="font-size:14px;text-align:center;">'+ user[i].name+'</div>'+
                            '      </div>'+
                            '         <div class="ub" style="position:absolute;left:5em;top:0.7em;">'+ phone +'</div>'+
                             '     <div class="ub ub_right" style="position:absolute;right:1em;"><div style="background-color:red;border-radius:0.5em;padding: 0.2em 0.5em;margin-top:0.7em;" ontouchstart="zy_touch()" onclick=Event.frienddetail(' + i + ')>'+addFd+'</div></div>'+
                            '</div>';   
               }
               $("#number").html(html);
            }
        });
	},
	frienddetail:function(i) {
      var item = GetLS("addlist")[i];
      SetLS("activity_detail", item);
      OpenNewWin("activity_detail");
    },
    frienddetailInit: function() {
        var friend = GetLS("activity_detail");
        $("#id").text(friend._id);
        $("#photo").css("background-image", "url("+ Core.id2url(friend) +")");
        $("#name").text(friend.name +"　"+ (friend.sex?friend.sex:""));
        $("#phone").text(CurrentUser.category==30?"电话:"+friend.phone:"Phone:"+friend.phone);
        var wu=CurrentUser.category==30?"无":"No";
        $("#country").text(CurrentUser.category==30?"国家:"+ (friend.courntry?friend.courntry:wu):"Country:"+ (friend.courntry?friend.courntry:wu));
        $("#interest").text(CurrentUser.category==30?"爱好:"+ (friend.interest?friend.interest:wu):"Interest:"+ (friend.interest?friend.interest:wu));
    },
    toAdd: function() {
                    SetLS("friendId",$("#id").text());
                    SetLS("friendph",$("#phone").text());
                    SetLS("friendnm",$("#name").text());
                    var person = ""+GetLS("searchInput");
                    var cid =CurrentUser._id;
                    var fid = GetLS("friendId");
                    var fph = ""+GetLS("friendph");
                    var fph1=fph.substring(fph.indexOf(":")+1);
                    var fnm = GetLS("friendnm");
                    var cph=CurrentUser.phone;
                    var adf=document.getElementById("btnCtn"); 
                    var chf=document.getElementById("btnCtnChat");  
                    if(CurrentUser.category==30){
                           if(cid==fid){
                               chf.setAttribute("style","display:none");
                              $alert("亲，不能添加自己为好友！");
                           }else{
                              var flag =false;
                              var length = CurrentUser.friends && CurrentUser.friends.length || 0;
                              for(var i=0; i<length; i++) {
                              var dbid=CurrentUser._id;
                              var fid = GetLS("friendId");
                              var dbfid=CurrentUser.friends[i].id;
                              var dbfr=CurrentUser.friends[i].from;
                              var st=CurrentUser.friends[i].status;
  
                                 var first = st==1;
                                 var second = (fid==dbfid || fid==dbfr);

                                 if((first&&second)==true){
                                     flag = true;
                                     adf.setAttribute("style","display:none");  
                                     SetLS("alist_chat", true);
                                     SetLS("chat_detail", GetLS("activity_detail"));
                                     //OpenNewWin("chat_detail");
                                 }
                                 }  
                                 if(!flag){
                                    chf.setAttribute("style","display:none"); 
                                    //OpenNewWin("activity_add_friend");    
                                 }
                           }
                    }else{
                              if(cid==fid){
                                  chf.setAttribute("style","display:none");
                              return $alertEn("You can't add you as a friend!");
                              PCall("event_detail","WinClose()");
                           }else{
                              var flag =false;
                              var length = CurrentUser.friends && CurrentUser.friends.length || 0;
                              for(var i=0; i<length; i++) {
                              var dbid=CurrentUser._id;
                              var fid = GetLS("friendId");
                              var dbfid=CurrentUser.friends[i].id;
                              var dbfr=CurrentUser.friends[i].from;
                              var st=CurrentUser.friends[i].status;
                                 var first = st==1;
                                 var second = (fid==dbfid || fid==dbfr);
                                 if((first&&second)==true){
                                     flag = true;
                                     adf.setAttribute("style","display:none");
                                     SetLS("alist_chat", true);
                                     SetLS("chat_detail", GetLS("activity_detail"));
                                     //OpenNewWin("chat_detail");
                                 }
                                 }  
                                 if(!flag){
                                    chf.setAttribute("style","display:none");
                                    //OpenNewWin("activity_add_friend");    
                                 }
                           }  
                   }
    },
    toAddInit: function() {
                    SetLS("friendId",$("#id").text());
                    SetLS("friendph",$("#phone").text());
                    SetLS("friendnm",$("#name").text());
                    var person = ""+GetLS("searchInput");
                    var cid =CurrentUser._id;
                    var fid = GetLS("friendId");
                    var fph = ""+GetLS("friendph");
                    var fph1=fph.substring(fph.indexOf(":")+1);
                    var fnm = GetLS("friendnm");
                    var cph=CurrentUser.phone;
                    var adf=document.getElementById("btnCtn"); 
                    var chf=document.getElementById("btnCtnChat");  
                    if(CurrentUser.category==30){
                           if(cid==fid){
                               chf.setAttribute("style","display:none");
                              $alert("亲，不能添加自己为好友！");
                           }else{
                              var flag =false;
                              var length = CurrentUser.friends && CurrentUser.friends.length || 0;
                              for(var i=0; i<length; i++) {
                              var dbid=CurrentUser._id;
                              var fid = GetLS("friendId");
                              var dbfid=CurrentUser.friends[i].id;
                              var dbfr=CurrentUser.friends[i].from;
                              var st=CurrentUser.friends[i].status;
  
                                 var first = st==1;
                                 var second = (fid==dbfid || fid==dbfr);

                                 if((first&&second)==true){
                                     flag = true;
                                     adf.setAttribute("style","display:none");  
                                     SetLS("alist_chat", true);
                                     SetLS("chat_detail", GetLS("activity_detail"));
                                     OpenNewWin("chat_detail");
                                 }
                                 }  
                                 if(!flag){
                                    chf.setAttribute("style","display:none"); 
                                    OpenNewWin("activity_add_friend");    
                                 }
                           }
                    }else{
                              if(cid==fid){
                                  chf.setAttribute("style","display:none");
                              return $alertEn("You can't add you as a friend!");
                              PCall("event_detail","WinClose()");
                           }else{
                              var flag =false;
                              var length = CurrentUser.friends && CurrentUser.friends.length || 0;
                              for(var i=0; i<length; i++) {
                              var dbid=CurrentUser._id;
                              var fid = GetLS("friendId");
                              var dbfid=CurrentUser.friends[i].id;
                              var dbfr=CurrentUser.friends[i].from;
                              var st=CurrentUser.friends[i].status;
                                 var first = st==1;
                                 var second = (fid==dbfid || fid==dbfr);
                                 if((first&&second)==true){
                                     flag = true;
                                     adf.setAttribute("style","display:none");
                                     SetLS("alist_chat", true);
                                     SetLS("chat_detail", GetLS("activity_detail"));
                                     OpenNewWin("chat_detail");
                                 }
                                 }  
                                 if(!flag){
                                    chf.setAttribute("style","display:none");
                                    OpenNewWin("activity_add_friend");    
                                 }
                           }  
                   }
    },
    addFriend:function(){
      //条件： 1  当前用户ID 2  要添加的人的ID   3 输入的验证信息
      //  访问后台    ajax  接口 
      $ajax({
            url: "/message/sdm",
            data: {
               cid:CurrentUser._id,
               fid:GetLS("friendId"),
               cont:$("#userInput").val()
            },
            success: function(res) {
                //$alert("验证消息已发送，请耐心等待好友回复哦!");
                PCall("activity_add_friend","WinClose()");
                PCall("event_detail","WinClose()");
            }
        });
    },
     addEventFriend:function(){
      //条件： 1  当前用户ID 2  要添加的人的ID   3 输入的验证信息
      //  访问后台    ajax  接口 
      $ajax({
            url: "/message/send",
            data: {
               cid:CurrentUser._id,
               fid:GetLS("friendId"),
               cont:$("#userInput").val()
            },
            success: function(res) {
                //$alert("验证消息已发送，请耐心等待好友回复哦!");
                PCall("activityevent_add_friend","WinClose()");
                PCall("event_frienddetail","WinClose()");
            }
        });
    },
	selectSheet: function(tab){
		var arr = "";
		switch(tab){
			case "category":
			    if(CurrentUser.category==30){
			       arr = eventArr;  
				}else{
				  arr = eventArr1;  
				}
				break;
			case "address":
			   if(CurrentUser.category==30){
				arr = addressArr;
			   }else{
			    arr = addressArr1;   
			   }
				break;
		}
		ActionSheet(CurrentUser.category==30?"请选择":"Please Check", CurrentUser.category==30?"取消":"Cancel", arr, function(data) {
            if(tab == "address"){
                if(data==4){
                    $("#" + tab).attr("data-num",data);
                    $("#" + tab).html('<input id="address1" type="text" class="ub ub-f1 uc-a1 input_sz" placeholder="Please Input"/>');            
                }else{
                    $("#" + tab).attr("data-num",data);
                    $("#" + tab).text(arr[data]);
                }
            }else if(tab == "category"){
                if(data==7){
                    $("#" + tab).attr("data-category",data);
                    $("#" + tab).html('<input id="category1" type="text" class="ub ub-f1 uc-a1 input_sz" placeholder="Please Input"/>');            
                }else{
                    $("#" + tab).attr("data-category",data);
                    $("#" + tab).text(arr[data]);
                }
            }else{
                    $("#" + tab).attr("data-num",data);
                    $("#" + tab).text(arr[data]);
            }
		});
	},
	uploadPhoto: function(){
		Upload.init(Core.API_VER + "/upload", function(res) {
			res = res[0];
		 	if (res.code) {
		 		$alert(res.codemsg);
		 		return;
		 	}                
            var url = res.result.url; 
            $("#photoList").append('<div data-photo="' + url + '" class="uw70 umauto photo"><img src="' + Core.IMG_VER + url + '" class="uw100"><img src="../img/icon_close.png" style="width:2em;height:2em;z-index:99999;position:absolute;top:-1em;right:-1em;" onclick="Event.closePhoto();"></div>');
		});
	},
	closePhoto: function(){
		var $this = $(event.currentTarget);
		$this.parent().remove();
	},
	startDatePicker: function(data){
		var date = data.year+"-"+data.month+"-"+data.day;
		$("#startDate").val(date);
	},
	startTimePicker: function(data){
		var date = data.hour+":"+data.minute;
		$("#startTime").val(date);
	},
	endDatePicker: function(data){
		var date = data.year+"-"+data.month+"-"+data.day;
		$("#endDate").val(date);
	},
	endTimePicker: function(data){
		var date = data.hour+":"+data.minute;
		$("#endTime").val(date);
	},
	add: function(){
		var data = new Object();
		if(!IsDefine($("#title").val())){
            return (CurrentUser.category==30?$alert("活动名称不能为空！"):$alertEn("The Name Of Activity is empty, please input its type"));
        }
        if(!IsDefine($("#content").val())){
            return (CurrentUser.category==30?$alert("内容不能为空！"):$alertEn("The Activity Description is empty, please input its type"));
        }
        if($("#category").data("category") == 7){
           if(!IsDefine($("#category1").val())){
            return (CurrentUser.category==30?$alert("活动类型不能为空！"):$alertEn("The Activity Type is empty, please select its type"));
           }else{
             data.activity =$("#category1").val();  
           }
        }
        if($("#address").data("num")==4){
            if(!IsDefine($("#address1").val())){
            return (CurrentUser.category==30?$alert("地点不能为空！"):$alertEn("The City is empty, please input its type"));
            }else{
            data.addressOther = $("#address1").val();
           }
        }
        if(!IsDefine($("#location").val())){
            return (CurrentUser.category==30?$alert("位置不能为空！"):$alertEn("The Location is empty, please input its type"));
        }
        if(!IsDefine($("#startDate").val())){
            return (CurrentUser.category==30?$alert("开始日期不能为空！"):$alertEn("The Start Time is empty, please input its type"));
        }
        if(!IsDefine($("#startTime").val())){
            return (CurrentUser.category==30?$alert("开始日期不能为空！"):$alertEn("The Start Time is empty, please input its type"));
        }
        if(!IsDefine($("#endDate").val())){
            return (CurrentUser.category==30?$alert("结束日期不能为空！"):$alertEn("The End Time is empty, please input its type"));
        }
        if(!IsDefine($("#endTime").val())){
            return (CurrentUser.category==30?$alert("结束日期不能为空！"):$alertEn("The End Time is empty, please input its type"));
        }
        if(!IsDefine($("#name").val())){
            return (CurrentUser.category==30?$alert("联系人不能为空！"):$alertEn("The Contact Person is empty, please input its type"));
        }
        if(!IsDefine($("#phone").val())){
            return (CurrentUser.category==30?$alert("电话不能为空！"):$alertEn("The Phone No is empty, please input its type"));
        }
        // if(!IsDefine($("#category").data("category"))){
            // return (CurrentUser.category==30?$alert("活动类型不能为空！"):$alertEn("The Activity Type is empty, please select its type!"));
        // }
		// data.category = $("#category").data("category")-0+1;
		data.category = $("#category").data("category");
		if(data.category == 7){
		    data.activity =$("#category1").val();
		}
		$("body").find(".value").each(function(e){
			data[$(this).attr("id")] = $(this).val();
		});
		data.start = $("#startDate").val() + " " + $("#startTime").val();
		data.end = $("#endDate").val() + " " + $("#endTime").val();
		data.from = CurrentUser._id;
		//data.address = $("#address").text();
		data.address = $("#address").data("num");
		if(data.address==4){
           data.addressOther = $("#address1").val();
        }
		data.photo = new Array();
		$("#photoList").find(".photo").each(function(){
			data.photo.push($(this).data("photo"));
		});
		$ajax({
			url: "/event/upsert",
			data: data,
			success: function(res){
			    var ml=CurrentUser.category==30?"ch/":"en/";
				PCall("../"+ml+"event","CCall('Event.InitBeijing()')");
				// PCall("../"+ml+"event","CCall('Event.attendInit()')");
				// PCall("../"+ml+"event","CCall('Event.myInit()')");
				PCall("event_add","WinClose()");
			}
		});
	},
	editInit:function(){
	    var data = GetLS("event");
        $(".value").each(function(){
            if ($(this).attr("id") == "category"){
                if(data.category == 8){
                    $(this).text(data.activity);
                }else{
                    CurrentUser.category==30?$(this).text(eventArrText[data.category]):$(this).text(eventArrText1[data.category]);
                }
            }else if ($(this).attr("id") == "start" || $(this).attr("id") == "end"){
                $(this).text(data[$(this).attr("id")]?new Date(data[$(this).attr("id")]).pattern("yyyy-MM-dd HH:mm"):"");
            }else{
                $(this).text(data[$(this).attr("id")]);
            }
        });
                    if(data.category==0){
                       $("#category").text("Expats Activities");
                    }
                    if(data.category==1){
                       $("#category").text("Topic");
                    }
                    if(data.category==2){
                       $("#category").text("Picnic");
                    }
                    if(data.category==3){
                        $("#category").text("Hiking");
                    }
                    if(data.category==4){
                       $("#category").text("Riding");
                    }
                    if(data.category==5){
                       $("#category").text("Forum");
                    }
                    if(data.category==6){
                       $("#category").text("Debate");
                    }
                    if(data.category==7){
                       $("#category").html('<input id="category1" type="text" class="ub ub-f1 uc-a1 input_sz" placeholder="Please Input"/>');            
                        $("#category1").val(data.activity);
                        $("#category").attr("data-category",data.category);
                    }
                    if(data.address==0){
                       $("#address").text("BeiJing");
                       $("#address").attr("data-num",data.address);
                    }
                    if(data.address==1){
                       $("#address").text("ShangHai");
                       $("#address").attr("data-num",data.address);
                    }
                    if(data.address==2){
                       $("#address").text("GuangZhou");
                       $("#address").attr("data-num",data.address);
                    }
                    if(data.address==3){
                       $("#address").text("ShenZhens");
                       $("#address").attr("data-num",data.address);
                    }
                    if(data.address==4){
                       $("#address").html('<input id="address1" type="text" class="ub ub-f1 uc-a1 input_sz" placeholder="Please Input"/>');            
                       $("#address1").val(data.addressOther);
                       $("#address").attr("data-num",data.address);
                    }
        $("#title").val(data.title);
        $("#location").val(data.location);
        $("#phone").val(data.phone);
        $("#name").val(data.name);
        $("#email").val(data.email);
        $("#fee").val(data.fee);
        $("#startDate").val( (new Date(data.start)).pattern('yyyy-MM-dd'));
        $("#startTime").val( (new Date(data.start)).pattern('HH:mm:ss'));
        $("#endDate").val( (new Date(data.create)).pattern('yyyy-MM-dd'));
        $("#endTime").val( (new Date(data.start)).pattern('HH:mm:ss'));
        $.each(data.photo,function(i,item){
            $("#photoList").append('<div data-photo="set_bg.png" class="uw100 umauto uptb_p5 photo"><img src="' + Core.id2url(item,"photo") + '" class="uw100"></div>');
        });
	},
	edit: function(){
        var data = GetLS("event");
        if(!IsDefine($("#title").val())){
            return (CurrentUser.category==30?$alert("活动名称不能为空！"):$alertEn("The Name Of Activity is empty, please input its type"));
        }
        if(!IsDefine($("#content").val())){
            return (CurrentUser.category==30?$alert("内容不能为空！"):$alertEn("The Activity Description is empty, please input its type"));
        }
        if($("#category").data("category") == 7){
           if(!IsDefine($("#category1").val())){
            return (CurrentUser.category==30?$alert("活动类型不能为空！"):$alertEn("The Activity Type is empty, please select its type"));
           }else{
             data.activity =$("#category1").val();  
           }
        }
        if($("#address").data("num")==4){
            if(!IsDefine($("#address1").val())){
            return (CurrentUser.category==30?$alert("地点不能为空！"):$alertEn("The City is empty, please input its type"));
            }else{
            data.addressOther = $("#address1").val();
           }
        }
        if(!IsDefine($("#location").val())){
            return (CurrentUser.category==30?$alert("位置不能为空！"):$alertEn("The Location is empty, please input its type"));
        }
        if(!IsDefine($("#startDate").val())){
            return (CurrentUser.category==30?$alert("开始日期不能为空！"):$alertEn("The Start Time is empty, please input its type"));
        }
        if(!IsDefine($("#startTime").val())){
            return (CurrentUser.category==30?$alert("开始日期不能为空！"):$alertEn("The Start Time is empty, please input its type"));
        }
        if(!IsDefine($("#endDate").val())){
            return (CurrentUser.category==30?$alert("结束日期不能为空！"):$alertEn("The End Time is empty, please input its type"));
        }
        if(!IsDefine($("#endTime").val())){
            return (CurrentUser.category==30?$alert("结束日期不能为空！"):$alertEn("The End Time is empty, please input its type"));
        }
        if(!IsDefine($("#name").val())){
            return (CurrentUser.category==30?$alert("联系人不能为空！"):$alertEn("The Contact Person is empty, please input its type"));
        }
        if(!IsDefine($("#phone").val())){
            return (CurrentUser.category==30?$alert("电话不能为空！"):$alertEn("The Phone No is empty, please input its type"));
        }
        // if(!IsDefine($("#category").data("category"))){
            // return (CurrentUser.category==30?$alert("活动类型不能为空！"):$alertEn("The Activity Type is empty, please select its type!"));
        // }
        // data.category = $("#category").data("category")-0+1;
        data.category=$("#category").val();
        data.address=$("#address").val();
        data.category = $("#category").data("category");
        if(data.category == 7){
            data.activity =$("#category1").val();
        }
        $("body").find(".value").each(function(e){
            data[$(this).attr("id")] = $(this).val();
        });
        data.start = $("#startDate").val() + " " + $("#startTime").val();
        data.end = $("#endDate").val() + " " + $("#endTime").val();
        data.from = CurrentUser._id;
        //data.address = $("#address").text();
        data.address = $("#address").data("num");
        if(data.address==4){
           data.addressOther = $("#address1").val();
        }
        $.each(data.photo,function(i,item){
            $("#photoList").append('<div data-photo="set_bg.png" class="uw100 umauto uptb_p5 photo"><img src="' + Core.id2url(item,"photo") + '" class="uw100"></div>');
        });
        // data.photo = new Array();
        // console.log(data.photo);
        // $("#photoList").find(".photo").each(function(){
            // data.photo.push($(this).data("photo"));
        // });
        $ajax({
            url: "/event/upsert1",
            data: data,
            success: function(res){
                var ml=CurrentUser.category==30?"ch/":"en/";
                PCall("../"+ml+"event","CCall('Event.InitBeijing()')");
                PCall("../"+ml+"event","CCall('Event.InitShanghai()')");
                PCall("../"+ml+"event","CCall('Event.InitGuangzhou()')");
                PCall("../"+ml+"event","CCall('Event.InitShenzhen()')");
                PCall("../"+ml+"event","CCall('Event.InitOthers()')");
                PCall("event_edit","WinClose()");
            }
        });
    },
    remove: function() {
        uexWindow.confirm(CurrentUser.category==30?"警告":"Notice",CurrentUser.category==30?"确定要删除吗？":"Do you want to detete?",CurrentUser.category==30?"确定,取消":"Sure,Cancel");
            function cbConfirm(opId, dataType, ensure){
            if(ensure == 0){
            var event = GetLS("event");
            $ajax({
                url: "/event/remove",
                data: {_id: event._id},
                success: function(res) {
                    if(res.code)
                        return $alert(res.codemsg);
                    var ml=CurrentUser.category==30?"ch/":"en/";
                    PCall("../"+ml+"event","CCall('Event.InitBeijing()')");
                    PCall("../"+ml+"event","CCall('Event.InitShanghai()')");
                    PCall("../"+ml+"event","CCall('Event.InitGuangzhou()')");
                    PCall("../"+ml+"event","CCall('Event.InitShenzhen()')");
                    PCall("../"+ml+"event","CCall('Event.InitOthers()')");
                    PCall("event_edit","WinClose()");
                }
            });
          }
        }
        uexWindow.cbConfirm = cbConfirm; 
    },  
}